package org.bees.cms.service.bean.util.recovery;

import javax.annotation.Resource;
import javax.persistence.EntityManagerFactory;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/**
 * 这个切面主要为了实现 让整个系统的数据都支持伪删除和实际删除的特点，使用这个切面是伪删除，不使用就为实际删除，<br/>
 * 而且还支持恢复的功能,假如数据删除了,找到标记为删除了的 再删除一次就变为存在的
 * 
 * @author Young
 * 
 */
// @Aspect
// @Service
public class Recovery {
	@Resource(name = "entityManagerFactory")
	private EntityManagerFactory factory;

	@Pointcut(value = "execution(* org.bees.cms.service.Service.remove(..))")
	public void pointcut() {
	}

	@Before(value = "pointcut() && args(argument)")
	public void doBefore(Object argument) {
	}

	@Around(value = "pointcut()")
	public Object doAround(ProceedingJoinPoint point) throws Throwable {
		return point.proceed();
	}

	@AfterReturning(pointcut = "pointcut()", returning = "result")
	public void doReturn(int result) {
	}

	@After(value = "pointcut() && args(argument)")
	public void doFinish(Object argument) {
	}

	@AfterThrowing(pointcut = "pointcut()", throwing = "exception")
	public void doThrows(Exception exception) throws Throwable {
		throw exception;
	}

}
